package org.millioncall.yueyoga.admin.action;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.millioncall.yueyoga.admin.service.MemberStatService;
import org.millioncall.yueyoga.admin.service.stat.GroupByTableBuilder;
import org.millioncall.yueyoga.admin.service.stat.TableView;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 会员统计
 * 
 * @author zangjinyu
 * @version 1.0.0
 * 
 */
@Controller
public class MemberStatAction extends BaseAction {
	private MemberStatService memberStatService;

	public void setMemberStatService(MemberStatService memberStatService) {
		this.memberStatService = memberStatService;
	}

	@RequestMapping(value = "/memberStat.jhtml")
	public String toMemberStat(HttpServletRequest request,
			HttpServletResponse response, ModelMap model) {
		super.initFrontHeader(request, model);

		List<String> leftGroupBy = Arrays.asList("sex", "areaId", "marketingSource");
		List<String> topGroupBy = Arrays.asList("subStatus");

		List<Object[]> results = this.memberStatService.memberStatQuery(
				leftGroupBy, topGroupBy, "memberId", "count");

		GroupByTableBuilder gbc = new GroupByTableBuilder(results,
				leftGroupBy.size(), topGroupBy.size());

		TableView tv = gbc.buildTable();

		model.put("caption", "会员数据统计");
		model.put("headerTrs", tv.getHeader());
		model.put("bodyTrs", tv.getBody());
		return "member_stat";
	}

}
